<?php
/**
 * beautycontroller.php
 * 
 * Create on 2015-04-02
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\index;
use \haibao\cms\business\control\pc\entity\ArticleEntity;

class BeautyController extends IndexController{

	const BEAUTY_TAG = 24;
	const BEAUTY_BLOG_CATEGORY = 94;
	const BEAUTY_EDITOR_TRY = 11004;
	
	public function __construct($updateTime = null,$controlId,$isPublish){

		$this->conditionTagId = self::BEAUTY_TAG;
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 显示模版内容（模版动态数据的绑定和模版输出）
	 * @param : String $content
	 * @param : Array $controlData;
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		
		if($controlData['manual']){
			// 第一屏
			$this->getFirstActualData($controlData['manual']);
		}
		
		$this->assign('hostUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU));
		$this->assign('moreUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU).'/cate/'.self::BEAUTY_BLOG_CATEGORY.'/0/');
		$this->assign('attentionType', \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER);
		$this->assign('tryHost', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_TRY));

		$this->assign('channelUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BEAUTY));
		$this->assign('tryUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_TRY));
		$this->assign('wordLinkList',$this->getWordLinkList($controlData['auto'],self::getTagChannel($this->conditionTagId)));
		$path = $this->generateHtmlPath(__CLASS__);
		$isNewHtml = $this->generateHtml($path,$content);

		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
	
	/**
	 * 获取美容第一屏数据
	 * 调出规则 与品牌一样
	 * @param : $dataCondition 数据条件
	 */
	public function getFirstActualData($dataCondition){

		$articleEntity = new ArticleEntity();
		$articleEntity->setLevel($dataCondition['level']);
		$articleEntity->setBigLevel($dataCondition['biglevel']);
		$articleEntity->setLimit($dataCondition['limit']);
		$articleEntity->setIsProImage(true);
		$articleEntity->setIsLeftJoinTag(true);
		$articleEntity->setIsPrimaryTag(false);
		$articleEntity->setIsConditionTag(true);
		$articleEntity->setIsReturnTag(true);
		$articleEntity->setIsImageColl(true);
		$articleEntity->setSource(__CLASS__);
		$articleEntity->setTagIds($this->conditionTagId);
		$articleEntity->setIsDebug(false);
		$articleEntity->setIsOnlyReturnPrimaryTag(true);
		$articleEntity->setProImageLevel(array(\haibao\cms\model\data\ArticleProImage::Level_FOUR));
		
		$this->articleAction->setArticleEnity($articleEntity);
		list($articles,$imageColls) = $this->articleAction->getListForNew();
		$mergeData = $this->mergeData($articles['list'],$imageColls['list'],$articleEntity->getLimit());
		
		list($firstLeftArticle,$firstRightArticle) = $this->packageMergeData(self::PACKAGE_DATA_TYPE_INDEX_BRAND_OR_BEAUTY_OR_LIFT, $mergeData, $articles, $imageColls);
		
		$this->assign('firstLeftArticle',json_decode(json_encode(array_values($firstLeftArticle))));
		$this->assign('firstRightArticle', json_decode(json_encode(array_values($firstRightArticle))));
	}
}